<template>
  <div class="setP">
    <u-navbar :is-back="true" title="修改密码" back-text="">
      <view
        class="slot-right"
        style="width: 100%; display: flex; justify-content: flex-end"
      >
        <!-- <div>
                <image @click="goSettingM" style="width: 1rem;padding: 1rem;" src="../../style/image/my/设 置.png" alt="">
                </div> -->
      </view>
    </u-navbar>

    <div class="inputS">
      <u-form :model="form" ref="uForm">
        <u-form-item
          placeholder="123"
          style="padding: 0.7rem 1rem"
          prop="name"
          label-width="auto"
          label="旧密码"
          ><u-input placeholder="请输入旧密码" v-model="form.pwd"
        /></u-form-item>
        <div style="background-color: #f4f5f7; height: 0.5rem"></div>
        <u-form-item
          style="padding: 0.7rem 1rem"
          prop="intro"
          label-width="auto"
          label="请输入新密码"
          ><u-input placeholder="请输入新密码" v-model="form.newPwd"
        /></u-form-item>
        <u-form-item
          style="padding: 0.7rem 1rem"
          prop="sex"
          label-width="auto"
          label="请确认新密码"
          ><u-input placeholder="请确认新密码" v-model="form.sureNewPwd"
        /></u-form-item>
      </u-form>
    </div>

    <view class="footP">
      <view
        @click="modifiyM"
        style="padding: 0.7rem; display: flex; align-items: center"
      >
        <!-- <image style="width: 1rem;" src="../../style/image/cargo/add.jpg" alt=""> -->
        <view style="color: white; margin-left: 0.2rem">确认修改</view>
      </view>
    </view>
  </div>
</template>

<script lang='ts' >
import { Component, Prop, Vue, Watch, Emit } from "vue-property-decorator";
import uNavbar from '@/uview-ui/components/u-navbar/u-navbar.vue'
 import uForm from  '../../uview-ui/components/u-form/u-form.vue'
  import uFormItem from  '../../uview-ui/components/u-form-item/u-form-item.vue'
  import uInput  from '../../uview-ui/components/u-input/u-input.vue'

import { updatePwd } from "../../utils/uniApi";

@Component({
  //   @Component  是一个装修器   不可以在下面写语句
  name: "test",
  components:{
    'u-navbar':uNavbar,
    'u-form':uForm,
    'u-form-item':uFormItem,
    'u-input':uInput
  }
})
export default class extends Vue {
  @Prop({
    type: String, // 父组件传递给子组件的数据类型
    required: false, // 是否必填
    default: " ", // 默认值， 如果传入的是 Object，则要 default: ()=>({}) 参数为函数
  })
  msg!: string;

  public checked = true;

  public form = {
    pwd: "",
    newPwd: "",
    sureNewPwd: "",
  };
  public rules = {
    name: [
      {
        required: true,
        message: "请输入姓名",
        // 可以单个或者同时写两个触发验证方式
        trigger: ["change", "blur"],
      },
    ],
    intro: [
      {
        // min: 5,
        message: "简介不能少于5个字",
        // trigger: 'change'
      },
    ],
  };

  created() {}

  mounted() {
    //  console.log('父组件传递的参数:',this.$parent)   //暂时不考虑
  }

  modifiyM() {
    console.log("123213");

    if (this.form.newPwd == this.form.sureNewPwd) {
      let params = {
        userId:
          uni.getStorageSync("userId") == ""
            ? ""
            : parseInt(uni.getStorageSync("userId")),
        newPwd: this.form.newPwd, //新密码
        pwd: this.form.pwd, //旧密码
      };

      updatePwd(params).then((res: any) => {
        console.log(res);
        	uni.hideLoading();

        uni.showToast({
          title: res.data.message,
          icon: "none",
          duration: 2000,
        });


      }).then(()=>{

           setTimeout(()=>{
              uni.clearStorageSync();	

         uni.navigateTo({
      url: "../../pages/login/index",
    });
           },1000)

      });
    } else {
      uni.showToast({
        title: "请认真填写",
        icon: "none",
        duration: 2000,
      });
    }
  }

  loginOut() {
    console.log("2131312");

    uni.navigateTo({
      url: "../login/index",
    });
  }
}
</script>

<style  lang="scss"  scoped>
.u-border-bottom:after {
  border-bottom-width: 0px !important;
}

.hr {
  height: 1rem;
  background-color: #f3f5f7;
}

.set-text {
  font-size: 0.84rem;
  font-family: PingFang SC;
  font-weight: 400;
  color: #4a4a4a;
}

.footP {
  position: absolute;
  bottom: 0;
  background-color: #02af74;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
</style>